#define _GNU_SOURCE // 如是不声明gettid()不识别报错
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

void *first_thread(void *arg)
{
    printf("first线程(%d)开始执行\n", gettid());
    sleep(1);
    printf("first线程执行结束\n");
}
void *second_thread(void *arg)
{
    printf("second线程(%d)开始执行\n", gettid());
    sleep(1);
    printf("second线程执行结束\n");
}
int main(int argc, char const *argv[])
{
    printf("main线程(%d)开始执行\n", gettid());

    pthread_t first;
    pthread_t second;

    // 创建线程
    pthread_create(&first, NULL,first_thread, NULL);
    pthread_create(&second, NULL,second_thread, NULL);

    printf("main线程执行,线程1标识:%ld, 线程2标识:%ld \n", first, second);

    pthread_join(first, NULL);
    pthread_join(second, NULL);

    printf("main线程执行结束\n");
    return 0;
}
